package com.bkitmobile.kesu.android.GUI;

import com.bkitmobile.kesu.android.ClassInfo.CmtLocation;
import com.bkitmobile.kesu.android.ClassInfo.PlaceInfo;
import com.bkitmobile.kesu.android.connectServer.staticClass;

import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MapCommentDialog extends Dialog implements android.view.View.OnClickListener{
	private EditText cmt;
	private Button btnSend, btnCancel;
	private Context context;
	private PlaceInfo pInfo;
	private TextView title;
	public MapCommentDialog(Context context) {
		super(context);
		this.context = context;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.map_comment_make);
		cmt = (EditText) findViewById(R.id.map_cmt_newCmt);
		btnSend = (Button) findViewById(R.id.map_cmt_btnSend);
		btnCancel = (Button) findViewById(R.id.map_cmt_btnCancel);
		btnCancel.setOnClickListener(this);
		btnSend.setOnClickListener(this);
		title = (TextView) findViewById(R.id.map_cmt_title);
		
	}
	
	public void show(PlaceInfo info) {
		String title = context.getString(R.string.map_cmt_titleWriteCmtDialog);
		setTitle(title + " " + info.getName());
		pInfo = info;
		super.show();
	}
	
	public String getCmt() {
		Log.d("cmt", cmt.getText().toString());
		return cmt.getText().toString();
	}

	@Override
	public void onClick(View v) {
		if(v == btnSend){
			//do something
			if (pInfo == null) Log.e("null", "error for cmt");
			if (cmt == null) Log.e("null", "error for null cmt");
			
			pInfo.addCmt(new CmtLocation(staticClass.user, getCmt(), "moment ago"));
			String req = "<cmtPlace><lat>"
				+pInfo.getLatE6()+"<lng>"+pInfo.getLngE6()+"<cmt>"+getCmt();
			
			
			staticClass.socket.println(req);
		}
		dismiss();
		
	}
	private void setTitle(String title){
		this.title.setText(title);
	}

}
